package com.Txunda.fxw.ui.activity.other;

import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.Txunda.fxw.R;
import com.Txunda.fxw.base.utils.util.JSONUtils;
import com.Txunda.fxw.base.utils.util.L;
import com.Txunda.fxw.base.utils.util.ListUtils;
import com.Txunda.fxw.base.utils.util.MapUtils;
import com.Txunda.fxw.base.utils.util.StringUtils;
import com.Txunda.fxw.ui.adapter.BottomLawAdapter;
import com.Txunda.fxw.ui.adapter.Law_DetailAdapter;
import com.Txunda.fxw.ui.adapter.model.LawModel;
import com.Txunda.fxw.ui.base.BaseAty;
import com.Txunda.fxw.ui.callback.MyItemClickListener;
import com.Txunda.fxw.ui.http.Company;
import com.Txunda.fxw.ui.toolkit.util.DensityUtil;
import com.Txunda.fxw.ui.toolkit.util.PreferenceUtil;
import com.Txunda.fxw.ui.widget.XCSlideView;
import com.Txunda.fxw.view.RoundedImageView;
import com.Txunda.fxw.view.dialog.AlertDialog;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * 具体详情界面
 *
 * @author Administrator
 */
public class DetailAty extends BaseAty implements PlatformActionListener {

    @ViewInject(R.id.aty_title3_tv_center)
    private TextView aty_title3_tv_center;
    @ViewInject(R.id.aty_title3_tv_right2)
    private TextView aty_title3_tv_right2;
    @ViewInject(R.id.tv_recycler)
    private RecyclerView tv_recycler;
    @ViewInject(R.id.icon_logo)
    private RoundedImageView icon_logo;
    @ViewInject(R.id.linear_coffee)
    private LinearLayout linear_coffee; // 咖啡布局
    @ViewInject(R.id.linear_enterprise)
    private LinearLayout linear_enterprise; // 企业布局

    @ViewInject(R.id.bottom_recycler)
    private RecyclerView bottom_recycler; // 底部的recyclerview

    @ViewInject(R.id.tv_time)
    private TextView tv_time; // 营业时间
    @ViewInject(R.id.tv_money)
    private TextView tv_money;
    @ViewInject(R.id.tv_address)
    private TextView tv_address;
    @ViewInject(R.id.tv_special)
    private TextView tv_special;
    @ViewInject(R.id.tv_idea)
    private TextView tv_idea;
    @ViewInject(R.id.tv_brand)
    private TextView tv_brand;
    @ViewInject(R.id.tv_product)
    private TextView tv_product;
    @ViewInject(R.id.tv_company_address)
    private TextView tv_company_address;
    @ViewInject(R.id.tv_company_special)
    private TextView tv_company_special;

    @ViewInject(R.id.img_pic)
    private ImageView img_pic;
    @ViewInject(R.id.tv_title)
    private TextView tv_title;
    @ViewInject(R.id.tv_name_wechat)
    private TextView tv_name_wechat;
    @ViewInject(R.id.linear_more_wechat)
    private RelativeLayout linear_more_wechat;

    @ViewInject(R.id.tv_phone)
    private TextView tv_phone;
    @ViewInject(R.id.tv_phone2)
    private TextView tv_phone2;

    private Law_DetailAdapter detail_adapter;

    private XCSlideView mSlideViewRight;
    private float mScreenHeight;
    private LinearLayout linear_top;
    private LinearLayout linear_bottom;
    private MyItemClickListener itemClickListener;


    private BottomLawAdapter bottomAdapter;


    @SuppressLint("HandlerLeak")
    Handler handler2 = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    showToast("微博分享成功");
                    finish();
                    break;
                case 2:
                    showToast("成功分享给微信好友"); // 分享到微信
                    finish();
                    break;
                case 3:
                    showToast("朋友圈分享成功"); // 分享到微信朋友圈
                    finish();
                    break;
                case 4:
                    showToast("QQ空间分享成功");
                    finish();
                    break;
                case 5:
                    showToast("分享已取消");
                    break;
                case 6:
                    showToast("分享失败");
                    break;
                default:
                    break;
            }
        }
    };

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {

            switch (msg.what) {
                case 1:
                    linear_top.setVisibility(View.VISIBLE);
                    linear_bottom.setVisibility(View.GONE);
                    ValueAnimator animator2 = ValueAnimator.ofFloat(0, mScreenHeight);
                    animator2.setTarget(linear_bottom);
                    animator2.setDuration(1000).start();
                    animator2.addUpdateListener(new AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            linear_bottom.setTranslationY((Float) animation.getAnimatedValue());
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    };
    private LinearLayout linear_phone;
    private TextView tv_collect;
    private String class_id;

    private Company company;
    private ArrayList<Map<String, String>> bottom_list_data;

    private List<LawModel> llist_data;

    private String lat;
    private String lnt;
    private String company_name;
    private String pic;
    private String address;

    Drawable img_collect;
    Drawable img_not_collect;

    private SharedPreferences sp;
    private SharedPreferences.Editor edit;


    /**
     * 历史收藏
     */
    protected String history;
    private String com_id;
    private boolean isCollect;
    private String url;
    private String collect_id;
    private String per_url;
    private String special_food_content_url;
    private String wechat_url;
    private String brand_content_url;
    private String product_url;
    private String company_special_url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String area_name = PreferenceUtil.readString(getApplicationContext(), PreferenceUtil.sp_mode);
        String district_name = getIntent().getStringExtra("district_name");
        if (district_name == null || district_name.equals("")) {
            aty_title3_tv_right2.setText(area_name);
        } else {
            aty_title3_tv_right2.setText(district_name);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        showProgressDialog();
        company.companyDetail(com_id, class_id, this);
        collect_id = sp.getString("history_collect", "");
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
        if (MapUtils.isEmpty(map))
            return;
        if (requestUrl.contains("companyDetail")) { // 商家详情
            Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
            if (MapUtils.isEmpty(data))
                return;
            bottom_list_data = JSONUtils.parseKeyAndValueToMapList(data.get("shop_list"));
            if (ListUtils.isEmpty(bottom_list_data))
                return;
            if (bottom_list_data.size() == 1) {
                Map<String, String> bld1 = new HashMap<>();
                bld1.put("com_id", "");
                bld1.put("class_id", "");
                bld1.put("name", "");
                bld1.put("type", "0");
                bld1.put("o_id", "");
                bld1.put("district_id", "");
                Map<String, String> bld2 = new HashMap<>();
                bld2.put("com_id", "");
                bld2.put("class_id", "");
                bld2.put("name", "");
                bld2.put("type", "0");
                bld2.put("o_id", "");
                bld2.put("district_id", "");
                bottom_list_data.add(0, bld2);
                bottom_list_data.add(0, bld1);
            } else if (bottom_list_data.size() == 2) {
                Map<String, String> bld3 = new HashMap<>();
                bld3.put("com_id", "");
                bld3.put("class_id", "");
                bld3.put("name", "");
                bld3.put("type", "0");
                bld3.put("o_id", "");
                bld3.put("district_id", "");
                bottom_list_data.add(0, bld3);
            }
            bottomAdapter.setList(bottom_list_data);
            bottom_recycler.setAdapter(bottomAdapter);

            final String tel = data.get("tel"); // 商家电话
            tv_phone.setText(tel);
            tv_phone2.setText(tel);
            // 电话
            linear_phone.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AlertDialog(DetailAty.this).builder().setTitle("提示").setMsg("tel: " + tel)
                            .setPositiveButton("确认", new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(("tel: ") + tel));
                                    startActivity(intent);

                                }
                            }).setNegativeButton("取消", new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    }).show();
                }
            });
            com_id = data.get("com_id");
            // 加载数据
            String is_book = data.get("is_book"); // 1有书房
            String is_coffee = data.get("is_coffe"); // 1.有咖啡
            String is_cake = data.get("is_cake"); // 1有糕点
            String is_tea_water = data.get("is_tea_water"); // 1有茶水
            String is_animal = data.get("is_animal"); // 1有动物
            String is_stay = data.get("is_stay"); // 1有住宿
            String is_fallow = data.get("is_fallow"); // 1有休闲
            String is_shop = data.get("is_shop"); // 1能购物
            String is_eat = data.get("is_eat"); // 1能餐饮
            String is_pick = data.get("is_pick"); // 1能采摘
            // 新加
            String is_qi = data.get("is_qi"); // 1能骑行
            String is_tu = data.get("is_tu"); // 1能徒步
            String is_ye = data.get("is_ye"); // 1能野钓
            String is_lu = data.get("is_lu"); // 1能露营
            String is_nong = data.get("is_nong"); // 1能农场
            String is_yang = data.get("is_yang"); // 1能养老
            String is_shou = data.get("is_shou"); // 1能手工
            String is_cha = data.get("is_cha"); // 1能茶园
            String is_yin = data.get("is_yin"); // 1能音乐

            per_url = data.get("per_url");
            special_food_content_url = data.get("special_food_content_url"); // 特色餐饮介绍链接
            wechat_url = data.get("wechat_url"); // 微信介绍链接
            brand_content_url = data.get("brand_content_url"); // 品牌链接
            product_url = data.get("product_url"); // 产品介绍链接
            company_special_url = data.get("company_special_url"); // 公司特色介绍

            String wechat = data.get("wechat");

            if (wechat == null || wechat.equals("")) {
                linear_more_wechat.setVisibility(View.GONE);
            } else {
                linear_more_wechat.setVisibility(View.VISIBLE);
                tv_name_wechat.setText(wechat);
            }

            LawModel lawModel;
            if ("1".equals(is_book)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_bookstore);
                lawModel.setTitle("书店");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_coffee)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_detail_coffee);
                lawModel.setTitle("咖啡");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_cake)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_gaodian);
                lawModel.setTitle("糕点");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_tea_water)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_detail_tea_drink);
                lawModel.setTitle("茶水");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_animal)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_animal);
                lawModel.setTitle("动物");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_stay)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_detail_hotal);
                lawModel.setTitle("住宿");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_fallow)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_detail_game);
                lawModel.setTitle("休闲");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_shop)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_shopping);
                lawModel.setTitle("购物");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_eat)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_eat);
                lawModel.setTitle("餐饮");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_pick)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_pick);
                lawModel.setTitle("采摘");
                llist_data.add(lawModel);
            }
            // 新加的
            if ("1".equals(is_qi)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_qixing);
                lawModel.setTitle("骑行");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_tu)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_tubu);
                lawModel.setTitle("徒步");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_ye)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_yediao);
                lawModel.setTitle("野钓");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_lu)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_luying);
                lawModel.setTitle("露营");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_nong)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_nongchang);
                lawModel.setTitle("农场");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_yang)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_yanglao);
                lawModel.setTitle("养老");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_shou)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_shougong);
                lawModel.setTitle("手工");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_cha)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_chayuan);
                lawModel.setTitle("茶园");
                llist_data.add(lawModel);
            }
            if ("1".equals(is_yin)) {
                lawModel = new LawModel();
                lawModel.setImg(R.drawable.icon_lh_yinyue);
                lawModel.setTitle("音乐");
                llist_data.add(lawModel);
            }

            detail_adapter.setList(llist_data);

            Log.e("=====长度=====", String.valueOf(llist_data.size()));
            Log.e("=====数据=====", String.valueOf(llist_data));

            tv_recycler.setAdapter(detail_adapter);

            tv_time.setText(data.get("shop_hours")); // 营业时间
            tv_money.setText(data.get("consume") + "元"); // 人均消费
            tv_address.setText(data.get("address")); // 地址
            tv_special.setText(data.get("special_food_content"));
            tv_idea.setText(data.get("idea")); // 企业理念
            String brand_content = data.get("brand_content");
            String product = data.get("product");
            tv_brand.setText(brand_content);
            tv_product.setText(product);
            tv_company_address.setText(data.get("address")); // 地址
            tv_company_special.setText(data.get("company_special")); // 公司特色

            Glide.with(this).load(data.get("pic")).into(img_pic);
            tv_title.setText(data.get("title"));

            url = data.get("url"); // 链接地址
            company_name = data.get("name"); // 商家名称
            pic = data.get("pic");
            address = data.get("address");

            lat = data.get("lat"); // 纬度
            lnt = data.get("lnt"); // 经度

            if (collect_id.contains(com_id)) { // 未收藏
                tv_collect.setText("已收藏");
                tv_collect.setCompoundDrawables(null, img_collect, null, null);
            } else { // 已收藏
                tv_collect.setText("收藏");
                tv_collect.setCompoundDrawables(null, img_not_collect, null, null);

            }
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.detail_aty;
    }

    @Override
    protected void initialized() {
        class_id = getIntent().getStringExtra("class_id");
        com_id = getIntent().getStringExtra("com_id");
        type = getIntent().getStringExtra("type") + class_id;
        sp = getSharedPreferences("COLLECT", Activity.MODE_PRIVATE);
        edit = sp.edit();


        img_collect = getResources().getDrawable(R.drawable.icon_yet_collect); // 收藏图标
        img_not_collect = getResources().getDrawable(R.drawable.icon_collect3); // 未收藏图标
        img_collect.setBounds(0, 0, img_collect.getMinimumWidth(), img_collect.getMinimumHeight());
        img_not_collect.setBounds(0, 0, img_not_collect.getMinimumWidth(), img_not_collect.getMinimumHeight());

        llist_data = new ArrayList<>();
        bottom_list_data = new ArrayList<>();
        String logo = PreferenceUtil.readString(getApplicationContext(), PreferenceUtil.sp_logo);

        Glide.with(this).load(logo).into(icon_logo);

        // 为底部的recyclerView设置LinearManager管理器对象
        bottom_recycler.setLayoutManager(
                new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));
        bottom_recycler.setItemAnimator(new DefaultItemAnimator());
        // 设置固定大小
        bottom_recycler.setHasFixedSize(true);
        bottomAdapter = new BottomLawAdapter(itemClickListener, DetailAty.this);

        company = new Company();
        String name = getIntent().getStringExtra("name");
        if ("3".equals(class_id)) { // 咖啡
            aty_title3_tv_center.setText(name);
            linear_coffee.setVisibility(View.VISIBLE);
            linear_enterprise.setVisibility(View.GONE);

        } else if ("5".equals(class_id)) { // 企业

            linear_coffee.setVisibility(View.GONE);
            linear_enterprise.setVisibility(View.VISIBLE);
            aty_title3_tv_center.setText(name);
        } else if ("4".equals(class_id)) {

            aty_title3_tv_center.setText(name);
            linear_coffee.setVisibility(View.VISIBLE);
            linear_enterprise.setVisibility(View.GONE);
        }

        // 动画
        DisplayMetrics outMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
        mScreenHeight = outMetrics.heightPixels;

        aty_title3_tv_right2.setVisibility(View.VISIBLE);
        // aty_title3_tv_right2.setText(area_name);
        // 设置LinearLayoutManager
        tv_recycler.setLayoutManager(
                new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));
        tv_recycler.setItemAnimator(new DefaultItemAnimator());
        // 设置固定大小
        tv_recycler.setHasFixedSize(true);
        // adapter = new DetailViewAdapter(DetailAty.this,itemClickListener);

        detail_adapter = new Law_DetailAdapter(DetailAty.this);
        // 侧滑
        Context mContext = this;
        // 屏幕宽度
        int mScreenWidth = DensityUtil.getScreenWidthAndHeight(mContext)[0];
        mSlideViewRight = XCSlideView.create(DetailAty.this, XCSlideView.Positon.RIGHT);
        View menuViewRight = LayoutInflater.from(mContext).inflate(R.layout.layout_slide, null);
        mSlideViewRight.setMenuView(DetailAty.this, menuViewRight);
        mSlideViewRight.setMenuWidth(mScreenWidth * 3 / 9);
        linear_phone = menuViewRight.findViewById(R.id.linear_phone);
        LinearLayout linear_setting = menuViewRight.findViewById(R.id.linear_setting);

        tv_collect = menuViewRight.findViewById(R.id.tv_collect);

        tv_collect.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                collect_id = sp.getString("history_collect", "");
                isCollect = collect_id.contains(com_id);
                if (!isCollect) { // 未收藏
                    tv_collect.setText("已收藏");
                    tv_collect.setCompoundDrawables(null, img_collect, null, null);
                    // 保存商家id的值
                    history = sp.getString("history_collect", "");

                    if (StringUtils.isEmpty(history)) {
                        history = com_id;
                    } else {
                        history += "," + com_id;
                    }
                    edit.putString("history_collect", history);
                    edit.apply();
                } else { // 收藏
                    tv_collect.setText("收藏");
                    tv_collect.setCompoundDrawables(null, img_not_collect, null, null);
                    // 去掉商家id的值
                    history = sp.getString("history_collect", "");
                    if (history.contains(com_id + ",")) {
                        history = history.replace(com_id + ",", "");
                    } else if (history.contains("," + com_id)) {
                        history = history.replace("," + com_id, "");
                    } else if (history.contains(com_id)) {
                        history = history.replace(com_id, "");
                    }
                    edit.putString("history_collect", history);
                    edit.commit();
                }

            }
        });

        // 设置
        linear_setting.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(SettingAty.class, null);
            }
        });

        LinearLayout weibo_linear = menuViewRight.findViewById(R.id.linear_weibo);
        LinearLayout weixin_linear = menuViewRight.findViewById(R.id.linear_weixin);
        LinearLayout friends_linear = menuViewRight.findViewById(R.id.linear_friends);
        LinearLayout qq_linear = menuViewRight.findViewById(R.id.linear_qq);
        LinearLayout leave_linear = menuViewRight.findViewById(R.id.linear_leave);
        LinearLayout linear_share = menuViewRight.findViewById(R.id.linear_share);
        linear_top = menuViewRight.findViewById(R.id.linear_top);
        linear_bottom = menuViewRight.findViewById(R.id.linear_bottom);
        LinearLayout linear_share2 = menuViewRight.findViewById(R.id.linear_share2);
        // 分享
        linear_share.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 向上走的动画
                if (linear_top.getVisibility() == View.VISIBLE) {

                    linear_top.setVisibility(View.GONE);
                    linear_bottom.setVisibility(View.VISIBLE);
                    ValueAnimator animator = ValueAnimator.ofFloat(mScreenHeight / 2, 0);
                    animator.setTarget(linear_bottom);
                    animator.setDuration(500).start();
                    animator.addUpdateListener(new AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            linear_bottom.setTranslationY((Float) animation.getAnimatedValue());
                        }
                    });
                }
            }
        });
        linear_share2.setOnClickListener(new OnClickListener() {
            private Timer timer;
            private TimerTask timetask;
            @Override
            public void onClick(View v) {

                if (linear_top.getVisibility() == View.GONE) {
                    linear_top.setVisibility(View.VISIBLE);
                    linear_bottom.setVisibility(View.GONE);
                    float start = 0 - mScreenHeight;
                    ValueAnimator animator = ValueAnimator.ofFloat(start, 0);
                    animator.setTarget(linear_top);
                    animator.setDuration(500).start();
                    animator.addUpdateListener(new AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            linear_top.setTranslationY((Float) animation.getAnimatedValue());
                        }
                    });
                    timer = new Timer();
                    timetask = new TimerTask() {

                        @Override
                        public void run() {
                            Message msg = new Message();
                            msg.what = 1;
                            handler.sendMessage(msg);
                        }
                    };
                    timer.schedule(timetask, 300);

                }

            }
        });
        // 评价
//        leave_linear.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
////                startActivity(LeaveMessageAty.class, null);
//                Bundle bundle = new Bundle();
//                bundle.putString("type", type);
//                startActivity(EvaluateAty.class, bundle);
//            }
//        });
        // 微博分享
        weibo_linear.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                showTips(R.drawable.error, "敬请期待");
            }
        });

        // 微信分享
        weixin_linear.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 判断是否安装微信
                if (isWeixinAvilible()) {
                    ShareParams sp_hy = new ShareParams();
                    sp_hy.setShareType(Platform.SHARE_WEBPAGE); // 非常重要：一定要设置分享属性
                    sp_hy.setTitle("峰行网"); // 分享标题
                    sp_hy.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp_hy.setUrl(url);
                    sp_hy.setImagePath(pic);
                    // sp_hy.setImageData(BitmapFactory.decodeResource(getResources(),
                    // R.drawable.ic_launcher));
                    // 3、非常重要：获取平台对象
                    Platform wechathy = ShareSDK.getPlatform(Wechat.NAME);
                    wechathy.setPlatformActionListener(DetailAty.this); // 设置分享事件回调
                    // 执行分享
                    wechathy.share(sp_hy);
                } else {
                    showToast("请下载并安装微信客户端");
                }
            }
        });
        friends_linear.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (isWeixinAvilible()) {
                    ShareParams sp = new ShareParams();
                    sp.setShareType(Platform.SHARE_WEBPAGE); // 非常重要：一定要设置分享属性
                    sp.setTitle("峰行网"); // 分享标题
                    sp.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp.setUrl(url);
                    sp.setImagePath(pic);
                    // 3、非常重要：获取平台对象
                    Platform wechatMoments = ShareSDK.getPlatform(WechatMoments.NAME);
                    wechatMoments.setPlatformActionListener(DetailAty.this); // 设置分享事件回调
                    // 执行分享
                    wechatMoments.share(sp);
                } else {
                    showToast("请下载并安装微信客户端");
                }
            }
        });
        // qq分享
        qq_linear.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                if (isQQClientAvailable()) {
                    ShareParams sp1 = new ShareParams();
                    sp1.setTitle("峰行网");// 分享标题
                    sp1.setText("峰行网超好用-分享给朋友吧~");// 分享文本
                    sp1.setTitleUrl(url); // 网友点进链接后，可以看到分享的详情
                    sp1.setSite("峰行网");
                    sp1.setSiteUrl(url);
                    sp1.setImagePath(pic);
                    // 3、非常重要：获取平台对象
                    Platform qzone = ShareSDK.getPlatform(QQ.NAME);
                    qzone.setPlatformActionListener(DetailAty.this);
                    // 执行分享
                    qzone.share(sp1);
                } else {
                    showToast("请下载并安装QQ客户端");
                }
            }
        });
    }

    @Override
    @OnClick({R.id.icon_logo, R.id.features_real, R.id.address_relat, R.id.realtive_product, R.id.enterpise_address,
            R.id.enterprise_speicial, R.id.tv_price, R.id.realtive_brand, R.id.img_pic, R.id.linear_more_wechat,
            R.id.linear_phone, R.id.linear_phone2})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.linear_phone2:
                try {
                    new AlertDialog(this).builder().setTitle("提示").setMsg("tel: " + tv_phone2.getText().toString())
                            .setPositiveButton("确认", new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(Intent.ACTION_CALL,
                                            Uri.parse("tel: " + tv_phone2.getText().toString()));
                                    startActivity(intent);

                                }
                            }).setNegativeButton("取消", new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    }).show();

                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.linear_phone:
                try {
                    new AlertDialog(this).builder().setTitle("提示").setMsg("tel: " + tv_phone.getText().toString())
                            .setPositiveButton("确认", new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(Intent.ACTION_CALL,
                                            Uri.parse("tel: " + tv_phone.getText().toString()));
                                    startActivity(intent);

                                }
                            }).setNegativeButton("取消", new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                        }
                    }).show();

                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.linear_more_wechat:
                try {
                    Uri uri = Uri.parse(wechat_url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // bundle =new Bundle();
                // bundle.putString("wechat_content", wechat_content);
                // startActivity(WechatIntroduceAty.class,bundle);

                break;
            case R.id.realtive_brand: // 品牌
                try {
                    Uri uri = Uri.parse(brand_content_url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // bundle =new Bundle();sdsadas
                // bundle.putString("from", "5");
                // bundle.putString("cut_brand", brand_content);
                // bundle.putString("com_id", com_id);
                // startActivity(FeaturesAty.class,bundle);
                break;
            case R.id.tv_price: // 查看价目表
                try {
                    Uri uri = Uri.parse(per_url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // bundle =new Bundle();
                // bundle.putString("from", "1");
                // bundle.putString("per_content", per_content);
                // bundle.putString("com_id", com_id);
                // startActivity(FeaturesAty.class,bundle);
                break;
            case R.id.enterprise_speicial: // 特色
                try {
                    Uri uri = Uri.parse(company_special_url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // bundle =new Bundle();
                // bundle.putString("from", "2");
                // bundle.putString("com_id", com_id);
                // bundle.putString("special_food_content", company_special);
                //
                // //bundle.putString("special_food_content", special_food_content);
                // startActivity(FeaturesAty.class,bundle);
                break;
            case R.id.enterpise_address: // 企业地址
                Bundle bundle = new Bundle();
                bundle.putString("lat", lat);
                bundle.putString("lnt", lnt);
                bundle.putString("name", company_name); // 商家名称
                bundle.putString("address", address);
                bundle.putString("pic", pic);
                startActivity(PathAty.class, bundle);
                break;
            case R.id.realtive_product: // 产品布局
                try {
                    Uri uri = Uri.parse(product_url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case R.id.icon_logo:
                if (!mSlideViewRight.isShow())
                    mSlideViewRight.show();
                break;
            case R.id.features_real: // 特色餐饮
                try {
                    Uri uri = Uri.parse(special_food_content_url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case R.id.address_relat: // 地址
                bundle = new Bundle();
                bundle.putString("lat", lat);
                bundle.putString("lnt", lnt);
                bundle.putString("name", company_name); // 商家名称
                bundle.putString("address", address);
                bundle.putString("pic", pic);
                startActivity(PathAty.class, bundle);
                break;
            case R.id.img_pic: // 图片链接
                try {
                    Uri uri = Uri.parse(url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } catch (Exception e) {
                    L.e(e.getMessage());
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void requestData() {

    }

    @Override
    public void onCancel(Platform arg0, int arg1) {
        handler2.sendEmptyMessage(5); // 取消分享

    }

    @Override
    public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) {
        if (arg0.getName().equals(SinaWeibo.NAME)) {// 判断成功的平台是不是新浪微博
            handler2.sendEmptyMessage(1); // 分享到微博
        } else if (arg0.getName().equals(Wechat.NAME)) {
            handler2.sendEmptyMessage(2); // 分享给微信好友
        } else if (arg0.getName().equals(WechatMoments.NAME)) {
            handler2.sendEmptyMessage(3); // 分享到微信朋友圈
        }
//        else if (arg0.getName().equals(QZone.NAME)) {
//            handler2.sendEmptyMessage(4); // 分享到qq空间
//        }
    }

    @Override
    public void onError(Platform arg0, int arg1, Throwable arg2) {
        arg2.printStackTrace();
        Message msg = new Message();
        msg.what = 6;
        msg.obj = arg2.getMessage();
        handler2.sendMessage(msg);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
